#pragma once

#include <xercesc/sax2/DefaultHandler.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/sax2/XMLReaderFactory.hpp>
#include <xercesc/util/OutOfMemoryException.hpp>

XERCES_CPP_NAMESPACE_USE

namespace xml
{
	class HC_API SAX2Handler : public DefaultHandler
	{
	public:
		SAX2Handler();
		virtual ~SAX2Handler();

		virtual void error(const SAXParseException& e);
		virtual void fatalError(const SAXParseException& e);
		virtual void warning(const SAXParseException& e);


		virtual void startElement(	const   XMLCh* const uri,const   XMLCh* const localname,const XMLCh* const qname,const Attributes& attributes);
		virtual void endElement( const XMLCh* const uri, const XMLCh* const localname,const XMLCh* const qname );
		virtual void characters( const XMLCh* const chars, const XMLSize_t length );
		virtual void resetDocument();
	    virtual void notationDecl(const XMLCh* const name, const XMLCh* const publicId, const XMLCh* const systemId);
		virtual void resetDocType();
		virtual void unparsedEntityDecl(const   XMLCh* const    name, const XMLCh* const publicId, const XMLCh* const systemId, const XMLCh* const notationName);
		virtual void endDocument();
		virtual void ignorableWhitespace(const XMLCh* const chars, const XMLSize_t length);
		virtual void setDocumentLocator(const Locator* const locator);
		virtual void startDocument();
		virtual void startPrefixMapping (const	XMLCh* const prefix,const XMLCh* const uri) ;
		virtual void endPrefixMapping(const	XMLCh* const prefix) ;
		virtual void skippedEntity(const XMLCh* const name) ;
		virtual InputSource* resolveEntity(const   XMLCh* const publicId, const XMLCh* const    systemId);
		virtual void resetErrors();
		virtual void comment( const   XMLCh* const chars, const XMLSize_t length);
		virtual void endCDATA();
		virtual void endDTD();
		virtual void endEntity(const XMLCh* const name);
		virtual void startCDATA();
		virtual void startDTD(const XMLCh* const    name, const XMLCh* const publicId, const XMLCh* const systemId);
		virtual void processingInstruction(const  XMLCh* const target, const XMLCh* const data);
		virtual void startEntity(const XMLCh* const name);
		virtual void elementDecl(const XMLCh* const name, const XMLCh* const model);
		virtual void attributeDecl(const XMLCh* const eName, const XMLCh* const aName
												, const XMLCh* const type, const XMLCh* const mode
												, const XMLCh* const value);
		virtual void internalEntityDecl(const XMLCh* const name, const XMLCh* const value);
		virtual void externalEntityDecl(const XMLCh* const name, const XMLCh* const publicId
													, const XMLCh* const systemId);
	};

	class HC_API SAX2Reader
	{
	public:
		SAX2Reader( const string& xmlFile, SAX2Handler* pSAX2Handler );		
		bool Read();
		string GetError();
	private:
		string			m_xmlFile;
		stringstream	m_strError;
		SAX2Handler*	m_pSAX2Handler;		
	};

}
